package w83b.w83bOperacionesPaso.w83bDatosMinisterio;

import java.io.InputStream;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFDataFormat;
import org.apache.poi.hssf.usermodel.HSSFFont;
import org.apache.poi.hssf.usermodel.HSSFFooter;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.util.HSSFColor;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import w83b.w83bBeans.W83bDatosMinisterioBean;
import w83b.w83bUtilidades.W83bClsEstilosExcel;
import w83b.w83bUtilidades.W83bUtilidadesExcel;
import w83b.w83bUtilidadesComunes.W83bClsConstantes;
import w83b.w83bUtilidadesComunes.W83bUtilidades;

import es.ejie.frmk.infraestructura.internacionalizacion.Q70GestorMensajesi18n;
import es.ejie.frmk.listeners.base.Q70ListenerUtils;
import es.ejie.frmk.presentacion.operacion.paso.Q70ActionPasoOP;
import es.ejie.frmk.presentacion.sesiondatos.Q70ContextoEJIE;



public class W83bCrearFicheroAnualMinisterioAction  extends Q70ActionPasoOP{
	
	protected void processOP(Q70ContextoEJIE contexto, ActionErrors errores, ActionMapping mapping,
			ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
		
		
	}

	protected ActionForward processForward(Q70ContextoEJIE contexto, ActionErrors errors, ActionMapping mapping, 
			ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
		//12-10 CON CODMADRID
		//plantillaInfAnualMinisterio.xls
	
		String strRutaExcel = Q70ListenerUtils.getApplicationProperty("RUTA_PLANTILLAS_EXCEL")+"plantillaInfAnualMinisterio.xls";
		
		InputStream inputStream = W83bCrearFicheroAnualMinisterioAction.class.getResourceAsStream(strRutaExcel);
		
		HSSFWorkbook wb = new HSSFWorkbook(inputStream); // Creación del libro
		wb.setSheetName(0,"RDO07-99"); // Creación de la hoja
		
        HSSFSheet sheet = wb.getSheetAt(0); // Creación de la hoja
        
        List listaDatos = (ArrayList)contexto.get("w83bResultadoDatosMinisterio");
        W83bDatosMinisterioBean criterios = (W83bDatosMinisterioBean)listaDatos.get(listaDatos.size()-1);
        
        W83bUtilidadesExcel excel = new W83bUtilidadesExcel(wb);

        String idioma = (String)contexto.get(W83bClsConstantes.CONSTANTE_CONTEXTO_IDIOMA);
        
        HSSFFooter footer = sheet.getFooter();
        footer.setRight(Q70GestorMensajesi18n.getSingleton().getMessage("w83bcomun","comun.label.pag",idioma,new String[]{footer.page()}));
       
        HSSFRow row = sheet.getRow((short)1); // Creación de la fila 1
        
        HSSFCell cell = row.getCell((short)0);
        cell.setCellValue(Q70GestorMensajesi18n.getSingleton().getMessage("w83bcomun","comun.datosMinisterio.eleccionesHasta",idioma)+" " + criterios.getFechaEleccion());
		 
        row = sheet.getRow((short)2); // Creación de la fila 1
        cell = row.getCell((short)0);
        cell.setCellValue("("+Q70GestorMensajesi18n.getSingleton().getMessage("w83bcomun","comun.datosMinisterio.registroHasta",idioma)+" " + criterios.getFechaRegistro() + ")");
        
        String sindiAnterior = "";
        String sConvenio = "";
        W83bDatosMinisterioBean elDato = new W83bDatosMinisterioBean();
        int fila = 5; 
        int filas = 0;
        
        //Antonio
        String[][] a = new String[listaDatos.size()-1][18];
        
        fila = -1;
        
        for(int i=0;i<(listaDatos.size()-1);i++){
        	elDato = (W83bDatosMinisterioBean)listaDatos.get(i);
        	
        	if(!(sindiAnterior).equals(elDato.getCodSindicato())){
        		fila++;
        	}
        	a[fila] [0] = elDato.getSiglasSindicato();
        	a[fila] [1] = elDato.getDescSindicato();
        	if(StringUtils.isNotEmpty(elDato.getCodMadrid())){
        		a[fila] [2] = elDato.getCodMadrid();
           	}else{
           		a[fila] [2] = "";
        	}
        	sConvenio = elDato.getConvenio().trim();
        	if("01".equals(elDato.getTerritorio())){
	        	if("1".equals(sConvenio)){
	            	if(StringUtils.isNotEmpty(elDato.getTotalDeleg())){
	    	        	//a[fila] [3] = elDato.getTotalDeleg();
			        	Double deleg = new Double(elDato.getTotalDeleg());//NOPMD
			        	if(StringUtils.isEmpty(a[fila] [3])){
			        		a[fila] [3] = "0";
			        	} 
			        	Double deleg1 = new Double(a[fila] [3]);//NOPMD
		            	a[fila] [3] = Integer.toString(deleg1.intValue() + deleg.intValue());
		            	
			        	//Double deleg = new Double(elDato.getTotalDeleg());
			        	if(StringUtils.isEmpty(a[fila] [17])){
			        		a[fila] [17] = "0";
			        	} 
			        	Double deleg2 = new Double(a[fila] [17]);//NOPMD
		            	a[fila] [17] = Integer.toString(deleg2.intValue() + deleg.intValue());
	    	        }else{
	    	        	//a[fila] [3] = "0";
			        	if(StringUtils.isEmpty(a[fila] [3])){
			        		a[fila] [3] = "0";
			        	} 
	    	        }

	        	}else{
	            	if(StringUtils.isNotEmpty(elDato.getTotalDeleg())){
	    	        	//a[fila] [4] = elDato.getTotalDeleg();
			        	Double deleg = new Double(elDato.getTotalDeleg());//NOPMD
			        	if(StringUtils.isEmpty(a[fila] [4])){
			        		a[fila] [4] = "0";
			        	} 
			        	Double deleg1 = new Double(a[fila] [4]);//NOPMD
		            	a[fila] [4] = Integer.toString(deleg1.intValue() + deleg.intValue());
		            	
			        	//Double deleg = new Double(elDato.getTotalDeleg());
			        	if(StringUtils.isEmpty(a[fila] [17])){
			        		a[fila] [17] = "0";
			        	}
			        	Double deleg2 = new Double(a[fila] [17]); //NOPMD
		            	a[fila] [17] = Integer.toString(deleg2.intValue() + deleg.intValue());
	    	        }else{
	    	        	//a[fila] [4] = "0";
			        	if(StringUtils.isEmpty(a[fila] [4])){
			        		a[fila] [4] = "0";
			        	} 
	    	        }
	        	}	        	
        	}else if("48".equals(elDato.getTerritorio())){
	        	if("1".equals(sConvenio)){
	            	if(StringUtils.isNotEmpty(elDato.getTotalDeleg())){
	    	        	//a[fila] [7] = elDato.getTotalDeleg();
			        	Double deleg = new Double(elDato.getTotalDeleg());//NOPMD
			        	if(StringUtils.isEmpty(a[fila] [7])){
			        		a[fila] [7] = "0";
			        	} 
			        	Double deleg1 = new Double(a[fila] [7]);//NOPMD
		            	a[fila] [7] = Integer.toString(deleg1.intValue() + deleg.intValue());
		            	
			        	//Double deleg = new Double(elDato.getTotalDeleg());
			        	if(StringUtils.isEmpty(a[fila] [17])){
			        		a[fila] [17] = "0";
			        	}
			        	Double deleg2 = new Double(a[fila] [17]); //NOPMD
		            	a[fila] [17] = Integer.toString(deleg2.intValue() + deleg.intValue());
	    	        }else{
	    	        	//a[fila] [7] = "0";
			        	if(StringUtils.isEmpty(a[fila] [7])){
			        		a[fila] [7] = "0";
			        	}
	    	        }
	        	}else{
	            	if(StringUtils.isNotEmpty(elDato.getTotalDeleg())){
	    	        	//a[fila] [8] = elDato.getTotalDeleg();
			        	Double deleg = new Double(elDato.getTotalDeleg());//NOPMD
			        	if(StringUtils.isEmpty(a[fila] [8])){
			        		a[fila] [8] = "0";
			        	} 
			        	Double deleg1 = new Double(a[fila] [8]);//NOPMD
		            	a[fila] [8] = Integer.toString(deleg1.intValue() + deleg.intValue());
		            	
			        	//Double deleg = new Double(elDato.getTotalDeleg());
			        	if(StringUtils.isEmpty(a[fila] [17])){
			        		a[fila] [17] = "0";
			        	}
			        	Double deleg2 = new Double(a[fila] [17]); //NOPMD
		            	a[fila] [17] = Integer.toString(deleg2.intValue() + deleg.intValue());
	    	        }else{
	    	        	//a[fila] [8] = "0";
			        	if(StringUtils.isEmpty(a[fila] [8])){
			        		a[fila] [8] = "0";
			        	} 
	    	        }
	        	}	        	
        	}else if("20".equals(elDato.getTerritorio())){
	        	if("1".equals(sConvenio)){
	            	if(StringUtils.isNotEmpty(elDato.getTotalDeleg())){
	    	        	//a[fila] [11] = elDato.getTotalDeleg();
			        	Double deleg = new Double(elDato.getTotalDeleg());//NOPMD
			        	if(StringUtils.isEmpty(a[fila] [11])){
			        		a[fila] [11] = "0";
			        	} 
			        	Double deleg1 = new Double(a[fila] [11]);//NOPMD
		            	a[fila] [11] = Integer.toString(deleg1.intValue() + deleg.intValue());
		            	
			        	//Double deleg = new Double(elDato.getTotalDeleg());
			        	if(StringUtils.isEmpty(a[fila] [17])){
			        		a[fila] [17] = "0";
			        	}
			        	Double deleg2 = new Double(a[fila] [17]); //NOPMD
		            	a[fila] [17] = Integer.toString(deleg2.intValue() + deleg.intValue());
	    	        }else{
	    	        	//a[fila] [11] = "0";
			        	if(StringUtils.isEmpty(a[fila] [11])){
			        		a[fila] [11] = "0";
			        	}
	    	        }
	        	}else{
	            	if(StringUtils.isNotEmpty(elDato.getTotalDeleg())){
	    	        	//a[fila] [12] = elDato.getTotalDeleg();
			        	Double deleg = new Double(elDato.getTotalDeleg());//NOPMD
			        	if(StringUtils.isEmpty(a[fila] [12])){
			        		a[fila] [12] = "0";
			        	} 
			        	Double deleg1 = new Double(a[fila] [12]);//NOPMD
		            	a[fila] [12] = Integer.toString(deleg1.intValue() + deleg.intValue());
		            	
			        	//Double deleg = new Double(elDato.getTotalDeleg());
			        	if(StringUtils.isEmpty(a[fila] [17])){
			        		a[fila] [17] = "0";
			        	}
			        	Double deleg2 = new Double(a[fila] [17]); //NOPMD
		            	a[fila] [17] = Integer.toString(deleg2.intValue() + deleg.intValue());
	    	        }else{
	    	        	//a[fila] [12] = "0";
			        	if(StringUtils.isEmpty(a[fila] [12])){
			        		a[fila] [12] = "0";
			        	}
	    	        }
	        	}	        	
        	}        	
        	  

        	
        	sindiAnterior = elDato.getCodSindicato();
        }
        
        String tempSiglasSindicato=" ";
        String tempDescSindicato=" ";
        String tempCodMadrid=" ";
        String tempFunc01=" ";
        String tempLabo01=" ";
        String tempFunc48=" ";
        String tempLabo48=" ";
        String tempFunc20=" ";
        String tempLabo20=" ";
        String tempTotalDeleg=" ";
        
//        for (int x=0; x < a.length; x++) {
//        	for (int y=x+1; y < a.length; y++) {
        for (int x=0; x <= fila; x++) { 
            for (int y=x+1; y <= fila; y++) {
        		int numx = Integer.parseInt(a[x] [17]);
        		int numy = Integer.parseInt(a[y] [17]);
        		if (numx < numy) {
        			tempSiglasSindicato = a[x] [0];
        			tempDescSindicato = a[x] [1];
        			tempCodMadrid = a[x] [2];
        			tempFunc01 = a[x] [3];
        			tempLabo01 = a[x] [4];
        			tempFunc48 = a[x] [7];
        			tempLabo48 = a[x] [8];
        			tempFunc20 = a[x] [11];
        			tempLabo20 = a[x] [12];
        			tempTotalDeleg = a[x] [17];
        			a[x] [0] = a[y] [0];//NOPMD
        			a[x] [1] = a[y] [1];//NOPMD
        			a[x] [2] = a[y] [2];//NOPMD
        			a[x] [3] = a[y] [3];//NOPMD
        			a[x] [4] = a[y] [4];//NOPMD
        			a[x] [7] = a[y] [7];//NOPMD
        			a[x] [8] = a[y] [8];//NOPMD
        			a[x] [11] = a[y] [11];//NOPMD
        			a[x] [12] = a[y] [12];//NOPMD
        			a[x] [17] = String.valueOf(numy);
        			a[y] [0] = tempSiglasSindicato;
        			a[y] [1] = tempDescSindicato;
        			a[y] [2] = tempCodMadrid;
        			a[y] [3] = tempFunc01;
        			a[y] [4] = tempLabo01;
        			a[y] [7] = tempFunc48;
        			a[y] [8] = tempLabo48;
        			a[y] [11] = tempFunc20;
        			a[y] [12] = tempLabo20;
        			a[y] [17] = tempTotalDeleg;
        		}      			
        	}
        }
        
        filas=fila + 1;
        fila = 5;
        //Fin Antonio
        
        //Antonio 27/03/2013
        //for(int i=0;i<(listaDatos.size()-1);i++){
        for(int i=0;i<(filas);i++){
        	//Antonio 27/03/2013
        	//elDato = (W83bDatosMinisterioBean)listaDatos.get(i); 
        	
        	//Antonio 27/03/2013
        	//if(!(sindiAnterior).equals(elDato.getCodSindicato())){
        		fila++;
        		row = sheet.createRow((short)fila); 
        		for(int j=3;j<19;j++){
        			cell = row.createCell((short)j);
        			
                	cell.setCellStyle(estiloFilaNumero(0,excel));
        		}
        	//}else{
        	//	row = sheet.getRow((short)fila);
        	//}
        	//Fin Antonio	
        	
        	cell = row.createCell((short)0);
        	//Antonio 27/03/2013
        	//cell.setCellValue(elDato.getSiglasSindicato());
        	cell.setCellValue(a[i] [0]);
        	cell.setCellStyle(estiloFila(0,excel));
        	
        	cell = row.createCell((short)1);
        	//Antonio 27/03/2013
        	//cell.setCellValue(elDato.getSiglasSindicato());
        	cell.setCellValue(a[i] [1]);
        	cell.setCellStyle(estiloFila(0,excel));
        	
        	cell = row.createCell((short)2);
        	//Antonio 27/03/2013
        	//if(StringUtils.isNotEmpty(elDato.getCodMadrid())){
        	if(StringUtils.isNotEmpty(a[i] [2])){
        		//Antonio 27/03/2013
        		//cell.setCellValue(W83bUtilidades.numero(elDato.getCodMadrid()));//no es este código, pero de momento no sabemos cual es	
        		cell.setCellValue(W83bUtilidades.numero(a[i] [2]));//no es este código, pero de momento no sabemos cual es
        	}        	
        	cell.setCellStyle(estiloFila(0,excel));
        	
        	//Antonio 27/03/2013
        	//if("01".equals(elDato.getTerritorio())){
	        //	if("1".equals(elDato.getConvenio())){
	        //		cell = row.createCell((short)3);	        		
	        //	}else{
	        //		cell = row.createCell((short)4);
	        //	}	        	
        	//}else if("48".equals(elDato.getTerritorio())){
	        //	if("1".equals(elDato.getConvenio())){
	        //		cell = row.createCell((short)7);	        		
	        //	}else{
	        //		cell = row.createCell((short)8);
	        //	}	        	
        	//}else if("20".equals(elDato.getTerritorio())){
	        //	if("1".equals(elDato.getConvenio())){
	        //		cell = row.createCell((short)11);	        		
	        //	}else{
	        //		cell = row.createCell((short)12);
	        //	}	        	
        	//}        	
        	  
        	//if(StringUtils.isNotEmpty(elDato.getTotalDeleg())){
	        //	Double deleg = new Double(elDato.getTotalDeleg()); //NOPMD
	        //  	cell.setCellValue(deleg.intValue());
	        //}else{
	        //	cell.setCellValue("0,00");
	        //}
        	//cell.setCellStyle(estiloFilaNumero(0,excel));
        	
        	cell = row.createCell((short)3);
        	if(StringUtils.isNotEmpty(a[i] [3])){
	        	Double deleg = new Double(a[i] [3]); //NOPMD
	           	cell.setCellValue(deleg.intValue());
	        }else{
	        	cell.setCellValue(0);
	        }
        	cell.setCellStyle(estiloFilaNumero(0,excel));
        	
        	cell = row.createCell((short)4);
        	if(StringUtils.isNotEmpty(a[i] [4])){
	        	Double deleg = new Double(a[i] [4]); //NOPMD
	           	cell.setCellValue(deleg.intValue());
	        }else{
	        	cell.setCellValue(0);
	        }
        	cell.setCellStyle(estiloFilaNumero(0,excel));

        	cell = row.createCell((short)7);
        	if(StringUtils.isNotEmpty(a[i] [7])){
	        	Double deleg = new Double(a[i] [7]); //NOPMD
	           	cell.setCellValue(deleg.intValue());
	        }else{
	        	cell.setCellValue(0);
	        }
        	cell.setCellStyle(estiloFilaNumero(0,excel));

        	cell = row.createCell((short)8);
        	if(StringUtils.isNotEmpty(a[i] [8])){
	        	Double deleg = new Double(a[i] [8]); //NOPMD
	           	cell.setCellValue(deleg.intValue());
	        }else{
	        	cell.setCellValue(0);
	        }
        	cell.setCellStyle(estiloFilaNumero(0,excel));
        
        	cell = row.createCell((short)11);
        	if(StringUtils.isNotEmpty(a[i] [11])){
	        	Double deleg = new Double(a[i] [11]); //NOPMD
	           	cell.setCellValue(deleg.intValue());
	        }else{
	        	cell.setCellValue(0);
	        }
        	cell.setCellStyle(estiloFilaNumero(0,excel));
        	
        	cell = row.createCell((short)12);
        	if(StringUtils.isNotEmpty(a[i] [12])){
	        	Double deleg = new Double(a[i] [12]); //NOPMD
	           	cell.setCellValue(deleg.intValue());
	        }else{
	        	cell.setCellValue(0);
	        }
        	cell.setCellStyle(estiloFilaNumero(0,excel));
        	

        	//sindiAnterior = elDato.getCodSindicato();
        	//Fin Antonio 27/03/2013
        }
        
      
        for(int i=6;i<=fila;i++){
        	row = sheet.getRow((short)i);
        	
        	cell = row.getCell((short)5);        	
        	HSSFCell cell3 = row.getCell((short)3);
        	HSSFCell cell4 = row.getCell((short)4);
        	cell.setCellValue(cell3.getNumericCellValue()+cell4.getNumericCellValue());
//        	cell.setCellValue(Integer.parseInt(cell3.getStringCellValue())+Integer.parseInt(cell4.getStringCellValue()));
        	cell.setCellStyle(estiloFilaNumero(0,excel));
        	 
        	int desde=i+1;
        	int hasta=fila+2;
        	cell = row.getCell((short)6);  
        	HSSFCell cell5 = row.getCell((short)5);
        	if(cell5.getNumericCellValue()==0){
        		cell.setCellValue(W83bUtilidades.numero("0"));
        	}else{
        		cell.setCellFormula("F"+desde+"/F"+hasta);
        	}
        	cell.setCellStyle(this.stylePorcentajesDcha(wb,excel));
        	
        	cell = row.getCell((short)9);        	
        	HSSFCell cell7 = row.getCell((short)7);
        	HSSFCell cell8 = row.getCell((short)8);
        	cell.setCellValue(cell7.getNumericCellValue()+cell8.getNumericCellValue());
        	cell.setCellStyle(estiloFilaNumero(0,excel));
        	 
        	cell = row.getCell((short)10); 
        	
        	HSSFCell cell9 = row.getCell((short)9);
        	if(cell9.getNumericCellValue()==0){
        		cell.setCellValue(W83bUtilidades.numero("0"));
        	}else{        	
        		cell.setCellFormula("J"+desde+"/J"+hasta);
        	}
        	cell.setCellStyle(this.stylePorcentajesDcha(wb,excel));

        	cell = row.getCell((short)13);        	
        	HSSFCell cell11 = row.getCell((short)11);
        	HSSFCell cell12 = row.getCell((short)12);
        	cell.setCellValue(cell11.getNumericCellValue()+cell12.getNumericCellValue());
        	cell.setCellStyle(estiloFilaNumero(0,excel));
        	
        	cell = row.getCell((short)14);  
        	HSSFCell cell13 = row.getCell((short)13);
        	if(cell13.getNumericCellValue()==0){
        		cell.setCellValue(W83bUtilidades.numero("0"));
        	}else{  
        		cell.setCellFormula("N"+desde+"/N"+hasta);
        	}
        	cell.setCellStyle(this.stylePorcentajesDcha(wb,excel));
        	
        	cell = row.getCell((short)15);    
        	cell.setCellFormula("D"+desde+"+H"+desde+"+L"+desde);
        	cell.setCellStyle(estiloFilaNumero(0,excel));
        	 
        	cell = row.getCell((short)16);    
        	cell.setCellFormula("E"+desde+"+I"+desde+"+M"+desde);
        	cell.setCellStyle(estiloFilaNumero(0,excel));
        	
        	cell = row.getCell((short)17);    
        	cell.setCellFormula("P"+desde+"+Q"+desde);
        	cell.setCellStyle(estiloFilaNumero(0,excel));

        	cell = row.getCell((short)18); 
        	cell.setCellFormula("R"+desde+"/R"+hasta);
        	cell.setCellStyle(this.stylePorcentajesDcha(wb,excel));
        	
        }
        
        fila++;
        row = sheet.createRow((short)fila);
        cell = row.createCell((short)0);  
        cell.setCellValue("TOTAL");
        cell.setCellStyle(W83bClsEstilosExcel.estiloNegritaTexto(wb));
      
        cell = row.createCell((short)1);  
        cell.setCellStyle(W83bClsEstilosExcel.estiloNegritaNumero(wb));
        cell = row.createCell((short)2);  
        cell.setCellStyle(W83bClsEstilosExcel.estiloNegritaNumero(wb));
     
        String colu = "";
        for(int k=3;k<19;k++){
        	 cell = row.createCell((short)k);
        	 colu = (String)W83bClsConstantes.correspondeciaNumeroColumnas.get(k+"");
        	 cell.setCellFormula("SUM("+colu+"7:"+colu+fila+")");
        	 if(k==6 || k==10 || k==14 || k==18){
        		 cell.setCellStyle(this.stylePorcentajesDchaNegrita(wb,excel));
        	 }else{
        		 cell.setCellStyle(W83bClsEstilosExcel.estiloNegritaNumero8(wb));
        	 }
        }
      
        
        byte[] bytesExcel = W83bUtilidadesExcel.fncExcelToBytes(wb);
        String nombreFichero = criterios.getFechaEleccion().substring(3,5)+"-"+criterios.getFechaEleccion().substring(8,10)+"CONCODMADRID.xls";
        response.setContentType("application/vnd.ms-excel");
        response.setContentLength(bytesExcel.length);
        response.setHeader("Content-Disposition","attachment; filename=" +nombreFichero);
        response.getOutputStream().write(bytesExcel);
        response.getOutputStream().flush();
        		
		return null;
	}
	
	private HSSFCellStyle estiloFilaNumero(int nFila, W83bUtilidadesExcel excel){
		if(nFila%2==0){
			return excel.styleTextoParNumero;
		}else{
			return excel.styleTextoImparNumero;			
		}
		
	}
	
	private HSSFCellStyle stylePorcentajesDcha(HSSFWorkbook wb, W83bUtilidadesExcel excel){
		HSSFDataFormat format = wb.createDataFormat();
   		HSSFCellStyle stylePorcentajesDcha =  wb.createCellStyle();
   		stylePorcentajesDcha.setAlignment(HSSFCellStyle.ALIGN_RIGHT); // Estilo alineación dercecha.			 
		HSSFFont fuente = wb.createFont();
	    fuente.setFontHeightInPoints((short) 8);
	    stylePorcentajesDcha.setFont(fuente);
	    stylePorcentajesDcha.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
	    stylePorcentajesDcha.setDataFormat(format.getFormat("0")); // Estilo de formato de número para que siempre saque como mínimo dos dígitos
	    stylePorcentajesDcha.setFillForegroundColor(HSSFColor.WHITE.index);
	    stylePorcentajesDcha.setBorderRight((short) 1);
	    stylePorcentajesDcha.setBorderLeft((short) 1);
	    stylePorcentajesDcha.setBorderBottom((short) 1);
	    stylePorcentajesDcha.setBorderTop((short) 1);
	    stylePorcentajesDcha.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
	    stylePorcentajesDcha.setDataFormat(format.getFormat("#,##0.00%"));
			
		return stylePorcentajesDcha;			
		
	}
	
	private HSSFCellStyle stylePorcentajesDchaNegrita(HSSFWorkbook wb, W83bUtilidadesExcel excel){
		HSSFDataFormat format = wb.createDataFormat();
		HSSFCellStyle stylePorcentajesDcha =  wb.createCellStyle();
		stylePorcentajesDcha.setAlignment(HSSFCellStyle.ALIGN_RIGHT); // Estilo alineación dercecha.			 
		HSSFFont fuente = wb.createFont();
		fuente.setFontHeightInPoints((short) 8);
		fuente.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
		stylePorcentajesDcha.setFont(fuente);
		stylePorcentajesDcha.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
		stylePorcentajesDcha.setDataFormat(format.getFormat("0")); // Estilo de formato de número para que siempre saque como mínimo dos dígitos
		stylePorcentajesDcha.setFillForegroundColor(HSSFColor.WHITE.index);
		stylePorcentajesDcha.setBorderRight((short) 1);
		stylePorcentajesDcha.setBorderLeft((short) 1);
		stylePorcentajesDcha.setBorderBottom((short) 1);
		stylePorcentajesDcha.setBorderTop((short) 1);
		stylePorcentajesDcha.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
		stylePorcentajesDcha.setDataFormat(format.getFormat("#,##0.00%"));
		
		return stylePorcentajesDcha;			
		
	}
	
	
	
	private HSSFCellStyle estiloFila(int nFila, W83bUtilidadesExcel excel){
		if(nFila%2==0){
			return excel.styleTextoPar;
		}else{
			return excel.styleTextoImpar;			
		}		
	}

}